<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $numShow=3;//so danh muc dau tien se liet ke tren trang
        $numShowItem=6;
    	// action body
        //lay 3 danh muc dau tien
        //goi serivce danh muc
        $seriveDM=Application_Model_service_DanhMucService::getInstance();
        $seriveDM instanceof Application_Model_serviceInf_DanhMucServiceInf;
        //goi service sanpham
        $serviceSP=Application_Model_service_SanPhamService::getInstance();
        $serviceSP instanceof Application_Model_serviceInf_SanPhamServiceInf;
        
        $arrayDM=$seriveDM->layDanhSachDanhMucSanPham();
        $result=array();
        //load san pham theo cac danh muc
        if(sizeof($arrayDM)>0){
        	if(sizeof($arrayDM)>=$numShow){
        		for ($index = 0; $index < $numShow; $index++) {
        			$Item=array();
        			$danhMuc=$arrayDM[$index];
        			$danhMuc instanceof Application_Model_bean_DanhMucSanPham;
        			$Item['danhMuc']=$danhMuc;
        			//load san pham cua danh muc do
        			$arrayItem=$serviceSP->getListSanPham($numShowItem,1,"",$danhMuc->getId(),0,"");
        			$Item['sanPham']=$arrayItem;
        			$result[$index]=$Item;
        		}
        	}	else{
        		foreach ($arrayDM as $value) {
        			$Item=array();
        			$danhMuc=$value;
        			$danhMuc instanceof Application_Model_bean_DanhMucSanPham;
        			$Item['danhMuc']=$danhMuc;
        			//load san pham cua danh muc do
        			$arrayItem=$serviceSP->getListSanPham($numShowItem,1,"",$danhMuc->getId(),0,"");
        			$Item['sanPham']=$arrayItem;
        			$result[$index]=$Item;
        		}
        	}
        }
        //add view
        $this->view->list=$result;
    }

    public function contactAction()
    {
        // action body
    }


}



